package Aaaaaa;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main2 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Set<String> set=new HashSet<>();
        int[] book = new int[n];
        int[] pos = new int[n];
        for(int i=0;i<n;i++){
            book[i]=sc.nextInt();
        }
        for(int i=0;i<n;i++){
            pos[i]=sc.nextInt();
        }
        dfs(book, pos, 0,set);
        System.out.println(set.size()% 1000000007);
    }

    private static void dfs(int[] book, int[] pos, int index,Set<String> set) {
        if (isTrue(book,pos)){
            set.add(Arrays.toString(book));
        }
        for(int i=index;i<book.length;i++){
            swap(book,i,index);
            dfs(book,pos,index+1,set);
            swap(book,i,index);
        }
    }

    private static boolean isTrue(int[] book, int[] pos) {
        for(int i=0;i<book.length;i++){
            if(book[i]>pos[i]){
                return false;
            }
        }
        return true;
    }

    public static void swap(int[] arr,int a,int b){
        int temp=arr[a];
        arr[a]=arr[b];
        arr[b]=temp;
    }

}
